<?php
class CustomSiteConfig extends DataObjectDecorator {
 
    function extraStatics() {
	return array(
            'db' => array(
                'Address' => 'Varchar(150)',
                'Zip' => 'Varchar(150)',
                'Country' => 'Varchar(150)',
                'Phone' => 'Varchar(150)',
                'Email' => 'Varchar(150)',
                'FacebookLink' => 'Varchar(250)',
                'ConstantContactLink' => 'Varchar(250)',
                'BigBannerLink' => 'Varchar(200)',
                'SmallBannerLink' => 'Varchar(200)'
            ),
            'has_one' => array(
                'BigBanner' => 'CustomSiteConfig_BigBanner',
                'SmallBanner' => 'CustomSiteConfig_SmallBanner',
            )
	);
    }
    

    public function updateCMSFields(FieldSet $fields) {
        $pageData = (DataObject::get('Page','Status = \'Published\''));
        if ($pageData) $pageSource = $pageData->toDropDownMap('URLSegment','Title');
        
        $fields->removeFieldFromTab('Root','Main');
        $fields->addFieldToTab('Root', new Tab('Welkom'), 'Access');
        $fields->addFieldToTab("Root.Welkom", new LiteralField("Logo", "<br /><br /><img src='./themes/default/images/logo.gif' alt='logo' /><br /><br />"));
        $fields->addFieldToTab("Root.Welkom", new TextField('Title', 'Titel van de website'));
        //$fields->addFieldToTab("Root.Welkom", new TextField('Tagline', 'Tagline'));
        
        $fields->addFieldToTab("Root.Welkom", new TextField("Address", "Adres", "", '40'));
        $fields->addFieldToTab("Root.Welkom", new TextField("Zip", "Postcode + Woonplaats", "", '60'));
        $fields->addFieldToTab("Root.Welkom", new TextField("Country", "Land", "", '40'));
        $fields->addFieldToTab("Root.Welkom", new TextField("Phone", "Telefoon", "", '40'));
        $fields->addFieldToTab("Root.Welkom", new TextField("Email", "Email", "", '40'));
        $fields->addFieldToTab("Root.Welkom", new TextField("FacebookLink", "Link naar Facebook", "", '200'));
        $fields->addFieldToTab("Root.Welkom", new TextField("ConstantContactLink", "Link naar Constant Contact", "", '200'));
        
        $fields->addFieldToTab('Root', new Tab('Banners'), 'Access');
        $fields->addFieldToTab("Root.Banners", new LiteralField("Logo3", "<br /><br /><img src='./themes/default/images/logo.gif' alt='logo' /><br /><br />"));
        $fields->addFieldToTab("Root.Banners", new LiteralField("Header1", "<br /><h3>Banner midden (488 x 181)</h3><br />"));
        $fields->addFieldToTab("Root.Banners", new ImageField("BigBanner", "Afbeelding"));
        $fields->addFieldToTab("Root.Banners", new TextField("BigBannerLink", "Link URL", "", '200'));
        
        $fields->addFieldToTab("Root.Banners", new LiteralField("Header2", "<br /<br /><h3>Banner rechts (222 x 181)</h3><br />"));
        $fields->addFieldToTab("Root.Banners", new ImageField("SmallBanner", "Afbeelding"));
        $fields->addFieldToTab("Root.Banners", new DropdownField('SmallBannerLink', 'Link naar pagina', $pageSource, '', '', 'Selecteer'));
        
        $fields->addFieldToTab('Root', new Tab('GoogleAnalytics'), 'Access');
        $fields->addFieldToTab("Root.GoogleAnalytics", new LiteralField("Logo3", "<br /><br /><img src='./themes/default/images/logo.gif' alt='logo' /><br /><br />"));
    }
    
}

class CustomSiteConfig_BigBanner extends Image { 
    
    function generateResized($gd) {
	return $gd->resize(488,181);	
    }
    
}

class CustomSiteConfig_SmallBanner extends Image {    
    
    function generateResized($gd) {
	return $gd->resize(222,181);	
    }
    
}